package com.artxis.cms.commands {
	
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.artxis.cms.business.MenusDelegate;
	import com.artxis.cms.events.MenusEvent;
	import com.artxis.cms.model.ViewModelLocator;
	
	import mx.controls.Alert;
	import mx.rpc.IResponder;
	import mx.utils.ArrayUtil;
	
	public class MenusCommand implements ICommand, IResponder {
	
		public var modelLocator:ViewModelLocator = ViewModelLocator.getInstance();
		
		public function MenusCommand() {
			
		}

		public function execute(event:CairngormEvent):void {
			
			var menusEvent:MenusEvent = event as MenusEvent;
			
			var delegate:MenusDelegate = new MenusDelegate( this );
			delegate.menus();
			
		}
		
		public function result( event:Object ):void {
			//modelLocator.siteConfigData = SiteConfigVO( event.result );
			if(event.result != "") {
				
				//modelLocator.MenusData = MenusVO( event.result );
				modelLocator.menusArrColl = new  XMLList(ArrayUtil.toArray( event.result));
				
			} else {
			
				mx.controls.Alert.show("error receiving site menu","Error");
				
			}
			
		}
		
		public function fault( event:Object ):void {
			Alert.show(String(event.fault.faultDetail));
			trace("CONNECTION ERROR");
			
		}
		
	}
}